package com.simen.downloader;

import com.simen.downloader.listener.DownloadListener;
import com.simen.downloader.model.BooleanHolder;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Created by zhangming on 16/4/11.
 */
final class DownloadInfor {
    final BooleanHolder run = new BooleanHolder(true);
    final DownloadOptions downloadOptions;
    final String key;
    final Loader loader;
    final Reference<DownloadListener> basedownload;

    public DownloadInfor(String key, DownloadOptions downloadOptions, DownloadListener
            downloadListener, DownloadListener baseListener) {
        this.key = key;
        this.downloadOptions = downloadOptions;
        this.loader = new Loader(downloadListener);
        this.basedownload = new WeakReference<DownloadListener>(baseListener);
    }

    /**
     * @return <b>true</b> - if view is collected by GC and Downloader should stop processing this
     * downloadtask;
     * <b>false</b> - otherwise
     */
    public boolean isCollected() {
        if (this.loader == null || this.loader.isCollected()) {
            return true;
        }
        return false;
    }
}
